//
//  HZWMovieTableViewCell.m
//  开心一刻
//
//  Created by lanou on 16/4/8.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "HZWMovieTableViewCell.h"


@implementation HZWMovieTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self =[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.aotuImage =[[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 40, 40)];
        self.aotuImage.layer.masksToBounds = YES;
        self.aotuImage.layer.cornerRadius = 20;
        
        self.aotunameLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 25, 150, 20)];
        self.aotunameLabel.font =[UIFont systemFontOfSize:13];
        
        
        self.jubaoButton = [UIButton buttonWithType:UIButtonTypeSystem];
        self.jubaoButton.frame = CGRectMake(KedWidth-45, 25, 30, 20);
        [self.jubaoButton setTitle:@"举报" forState:UIControlStateNormal];
        [self.jubaoButton setTintColor:[UIColor orangeColor]];
        self.jubaoButton .font =[UIFont systemFontOfSize:13];
        
        
        
        
        self.contentLabel =[[UILabel alloc]initWithFrame:CGRectMake(15, 60, KedWidth-30, 60)];
        self.contentLabel.font =[UIFont systemFontOfSize:15];
        self.contentLabel.numberOfLines = 0;
        
        
        UIView * view1 =[[UIView alloc]initWithFrame:CGRectMake(15, 125, 80, 20)];
       // view1.backgroundColor =[UIColor redColor];
        view1.layer.masksToBounds = YES;
        view1.layer.cornerRadius = 10;
        view1.layer.borderColor = [UIColor blackColor].CGColor;
        view1.layer.borderWidth = 1;
        
        self.style =[[UILabel alloc]init];
        self.style.frame = CGRectMake(15, 0, 80, 20);
        self.style.font = [UIFont systemFontOfSize:13];

        
        
        self.contentImage =[[UIImageView alloc]init];
        self.contentImage.frame = CGRectMake(15, 150, KedWidth-30,(KedWidth-30)/3*2);
        
        
        self.palyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.palyButton .backgroundColor = [UIColor blackColor];
        self.palyButton.alpha = 0.6;
        self.palyButton.layer.masksToBounds = YES;
        self.palyButton.layer.cornerRadius = 30;
        [self.palyButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
        self.palyButton.userInteractionEnabled =YES;
        self.contentImage.userInteractionEnabled = YES;
        [self.contentImage addSubview:_palyButton];
        
        
        self.detailImage = [[UIImageView alloc]init];
        self.detailImage.backgroundColor =[UIColor blackColor];
        self.detailImage.alpha = 0.6;
        [self.contentImage addSubview:_detailImage];
        
        
       
        
        self.playTimelabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, 200, 15)];
        self.playTimelabel.font = [UIFont systemFontOfSize:13];
        [self.playTimelabel setTextColor:[UIColor orangeColor]];
        self.allTime = [[UILabel alloc]init];
        [self.allTime setTextColor:[UIColor whiteColor]];
        self.allTime.font = [UIFont systemFontOfSize:13];
        [self.detailImage addSubview:_playTimelabel];
        [self.detailImage addSubview:_allTime];
        
        
        
        
        self.betterImage = [[UIImageView alloc]init];
        self.betterImage.layer.masksToBounds = YES;
        self.betterImage.layer.cornerRadius = 20;
        
        self.username = [[UILabel alloc]init];
        self.username .font = [UIFont systemFontOfSize:13];
        
        self.betterText = [[UILabel alloc]init];
        self.betterText.numberOfLines= 0;
        self.betterText .font = [UIFont systemFontOfSize:15];
        
        [self.contentView addSubview:_aotuImage];
        [self.contentView addSubview:_aotunameLabel];
        [self.contentView addSubview:_contentLabel];
        [self.contentView addSubview:_contentImage];
      //  [self.contentView addSubview:_style];
        [self.contentView addSubview:_betterImage];
        [self.contentView addSubview:_username];
        [self.contentView addSubview:_betterText];
        [self.contentView addSubview:_jubaoButton];
        [self.contentView addSubview:view1];
        [view1 addSubview:_style];
    }
    return self;
}
 //返回标题的高度实现方法
-(void)titleHight:(HZWMovieModel *)model
{
    CGRect bounds = [model.BetterText boundingRectWithSize:CGSizeMake(KedWidth -30, 10000) options:NSStringDrawingUsesLineFragmentOrigin  attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    
   
    if (model.width>KedWidth && model.height!= 0 )
    {
        self.detailImage.frame= CGRectMake(0, (KedWidth-30)*model.height/model.width-30, KedWidth-30, 30);
        self.allTime.frame = CGRectMake(self.detailImage.frame.size.width-45, 10, 60, 15);
        self.palyButton.frame = CGRectMake((KedWidth -30-60)/2, ((KedWidth-30)*model.height/model.width-60)/2, 60, 60);
        self.username.frame = CGRectMake(65, 150+(KedWidth-30)*model.height/model.width+15, 200, 20);
        self.betterText.frame = CGRectMake(65, 40+5+150+(KedWidth-30)*model.height/model.width, KedWidth-65, bounds.size.height);
        self.betterImage.frame = CGRectMake(15, 150+(KedWidth-30)*model.height/model.width, 40, 40);
    
        self.contentImage.frame = CGRectMake(15,150,(KedWidth-30) ,(KedWidth-30)*model.height/model.width);
    }
    else if(model.width == KedWidth && model.height!= 0)
    {
        self.palyButton.frame = CGRectMake((KedWidth -30-60)/2, ((KedWidth-30)-60)/2, 60, 60);
        self.username.frame = CGRectMake(65, 150+(KedWidth-30), 200, 20);
        self.betterImage.frame = CGRectMake(15, 150+(KedWidth-30), 40, 40);
        self.betterText.frame = CGRectMake(65, 40+5+150+(KedWidth-30), KedWidth-65, bounds.size.height);
        self.contentImage.frame = CGRectMake(15,150,(KedWidth-30) ,(KedWidth-30));
        
    }
    else if(model.width < KedWidth && model.height!= 0)
        
    {
        NSLog(@"%ld",model.height );
        self.detailImage.frame = CGRectMake(0, model.width*model.height/model.width-30, model.width, 30);
        self.allTime.frame = CGRectMake(self.detailImage.frame.size.width-45, 10, 60, 15);
        self.contentImage.frame = CGRectMake(15,150,model.width ,model.width*model.height/model.width);
        self.palyButton.frame = CGRectMake((KedWidth -30-60)/2, (model.width*model.height/model.width-60)/2, 60, 60);

        self.username.frame = CGRectMake(65, 150+model.width*model.height/model.width+15, 200, 20);
        self.betterImage.frame = CGRectMake(15, 150+model.width*model.height/model.width, 40, 40);
        self.betterText.frame = CGRectMake(65, 40+5+150+model.width*model.height/model.width, KedWidth-65, bounds.size.height);
        
    }
    
    
}
+(CGFloat)cellHight:(HZWMovieModel *)model
{
    if (model.BetterText !=nil)
    {
        CGRect bounds = [model.BetterText boundingRectWithSize:CGSizeMake(KedWidth-30, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
        
      //  return 40+5+150+(KedWidth-30)*model.height/model.width+bounds.size.height+18;
        if (model.width>KedWidth)
        {
            return 40+5+150+(KedWidth-30)*model.height/model.width+bounds.size.height+18;
            
        }
        else if (model.width==KedWidth)
        {
            return 40+5+150+(KedWidth-30)+bounds.size.height+18;
        }
        else{
            return 40+5+150+model.width*model.width/model.height+bounds.size.height+18;
        }

    }
    else{
        if (model.width>KedWidth)
        {
            return 150+(KedWidth-30)*model.height/model.width+10;
        }
        else if (model.width==model.height)
        {
            return 150+(KedWidth-30)*model.height/model.width+10;
            
        }
        else{
            return 150+model.width*model.width/model.height+10;
        }
       
    }
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
